<?php
include_once 'common/tools.php';

//启用一个带有ob_gzip压缩机的工作台
ob_start('ob_gzip');

$matchTime = $_GET["matchTime"];
$homeTeam = $_GET["homeTeam"];
$visitTeam = $_GET["visitTeam"];
$videoCategory = $_GET["videoCategory"];

$config = require 'conf/config.ini.php'; //加载公用config.ini.php

$conn = mysql_connect($config["DB_HOST"], $config["DB_USER"], $config["DB_PWD"]);
mysql_select_db($config["DB_NAME"], $conn);
mysql_query("SET NAMES utf8");

$sql = "select v.*,count(w.videoId) videoWatch from live_video v left join live_video_watch w on v.videoId = w.videoId " .
		"where v.homeTeam = '" . $visitTeam . "' and v.visitTeam = '" . $homeTeam . "' and v.videoCategory='" . $videoCategory . "' " .
		"and (date('" . $matchTime . "') between DATE_SUB(date('" . $matchTime . "'), INTERVAL 4 DAY) and DATE_SUB(date('" . $matchTime . "'), INTERVAL -3 DAY)) " .
		"group by v.videoId";
$videoList = mysql_query($sql, $conn);
if (mysql_num_rows($videoList) > 0) {
	while ($video = mysql_fetch_object($videoList)) {
		$videoArray[] = $video;
	}

	//echo '{"sql":"' . $sql . '","results":' . json_encode($matchArray) . '}';
	echo '{"result":"Y", "results":' . json_encode($videoArray) . '}';
} else {
	echo '{"sql":"' . $sql . '","result":"N"}';
}

//输出压缩成果
ob_end_flush();
?>
